package cn.jbolt.ai.klb.controller;

import cn.jbolt.ai.klb.entity.AiKnowledgeBase;
import cn.jbolt.ai.klb.service.AiKnowledgeBaseService;
import cn.jbolt.util.Result;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;

/**
 * AI知识库管理
 */
@Controller
@ResponseBody
@RequestMapping("/aiKnowledgeBase")
@Tag(name = "AI知识库管理Controller")
public class AiKnowledgeBaseController {

    @Autowired
    private AiKnowledgeBaseService knowledgeBaseService;

    @Operation(summary = "根据ID获取知识库信息", description = "根据ID获取知识库信息")
    @GetMapping("/getById/{id}")
    public Result getById(@PathVariable Long id) {

        return knowledgeBaseService.getKnowledgeBaseById(id);
    }

    @Operation(summary = "分页获取所有知识库信息", description = "获取所有知识库信息")
    @GetMapping("/list")
    public Result listByPage(
            @RequestParam(required = false) Boolean enable,
            @RequestParam(required = false) String keywords,
            Integer page, Integer pageSize) {
        return knowledgeBaseService.listByPage(enable, keywords, page, pageSize);
    }

    @Operation(summary = "下拉选获取所有知识库信息", description = "获取所有知识库信息")
    @GetMapping("/listAllEnabled")
    public Result listAllEnabled() {
        return knowledgeBaseService.listAllEnabled();
    }


    @Operation(summary = "添加新的知识库", description = "添加新的知识库")
    @PostMapping("/add")
    public Result add(@RequestBody AiKnowledgeBase knowledgeBase) {

        return knowledgeBaseService.add(knowledgeBase);
    }

    @Operation(summary = "更新知识库信息", description = "更新知识库信息")
    @PostMapping("/update")
    public Result update(@RequestBody AiKnowledgeBase knowledgeBase) {
        return knowledgeBaseService.update(knowledgeBase);
    }

    @Operation(summary = "删除知识库", description = "删除知识库")
    @GetMapping("/del/{id}")
    public Result del(@PathVariable Long id) {
        return knowledgeBaseService.del(id);
    }

    @Operation(summary = "修改知识库的启用状态", description = "修改知识库的启用状态")
    @GetMapping("/toggleEnable/{id}")
    public Result toggleEnable(@PathVariable Long id) {
        return knowledgeBaseService.toggleEnable(id);
    }


    @Operation(summary = "知识库检索", description = "知识库检索")
    @GetMapping("/getDocListByKnowledgeBaseId")
    Result getDocListByKnowledgeBaseId(Long knowledgeBaseId, String content, Integer limit, Double minScore) {
        return knowledgeBaseService.getDocListByKnowledgeBaseId(knowledgeBaseId, content, limit, minScore);
    }
}
